using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHealthChecks()
    .AddCheck("self", () => HealthCheckResult.Healthy());
builder.Services
    .AddHealthChecksUI()
    .AddInMemoryStorage();


var app = builder.Build();

app.Use(async(context, next) => {
    if (context.Request.Path == "/")
    {
        context.Response.Redirect("/hc-ui");
        return;
    }
    await next();
});

app.UseHealthChecksUI(config =>
{
    config.ResourcesPath = "/ui/resources" ;
    config.UIPath = "/hc-ui";
});
app.UseStaticFiles();

app.UseRouting();
app.MapHealthChecks("/liveness", new HealthCheckOptions
{
    Predicate = r => r.Name.Contains("self")
});

app.Run();
